<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>8.添加元素的多种操作技巧</title>
</head>
<body>
  <script>
    let array = ['hdcms','houdunren'];
    console.log(array[1]);
    // 追加元素
    array[array.length] ="cms";
    array[array.length] ="shop";
    console.table(array);//Array(4) 0: "hdcms" 1: "houdunren"2: "cms" 3: "shop"
    let hd = ['aa','bb'];
    array = [...array,...hd];
    console.log(array); //(6)['hdcms', 'houdunren', 'cms', 'shop', 'aa', 'bb']
    //扩展语法 添加元素，可以加多个元素
    array.push("psp","ai","qqs");
    console.log(array);//(9)['hdcms', 'houdunren', 'cms', 'shop', 'aa', 'bb', 'psp', 'ai', 'qqs']
    //返回值是数组changdu 
    let length = array.push("ok",...hd);
    console.log(array); //['hdcms', 'houdunren', 'cms', 'shop', 'aa', 'bb', 'psp', 'ai', 'qqs', 'ok', 'aa', 'bb']
    console.log(length);//12

    //生成随机数组
    function rangeArray(begin,end){
      const array = [];
      for(let i = begin;i<=end;i++){
        array.push(i);
      }

      return array;
    }

    console.table(rangeArray(11, 15));
  </script>
</body>
</html>